#include "informationline.h"
#include "logger.h"

using namespace views;
using namespace utilities;

InformationLine::InformationLine()
{
    initUI();
    setupUI();

    connect(_btnAutoDelete, SIGNAL(clicked()), this, SLOT(emitAutoDeletion()));
}

InformationLine::InformationLine(int id, LinkType type, QString linkText):
    _id(id)
{
    initUI();
    setType(type);
    setLinkText(linkText);
    setupUI();

    connect(_btnAutoDelete, SIGNAL(clicked()), this, SLOT(emitAutoDeletion()));
}

InformationLine::~InformationLine()
{
    delete _typeBox;
    delete _linkText;
    delete _btnAutoDelete;
}

void InformationLine::initUI()
{
    _typeBox        = new QComboBox;
    _linkText       = new QLineEdit;
    _btnAutoDelete  = new QPushButton(" Enlever");

    // Init widget attributes
    //_typeBox->setStyleSheet(QString::fromUtf8("font: 8pt \"Rockwell\"; font-weight: bold; color: black; background-color: white;"));
    _typeBox->setMinimumWidth(100);
    _typeBox->addItem(tr("Lien web"));
    _typeBox->addItem(tr("Vidéo"));
    _typeBox->addItem(tr("Image"));
    _typeBox->addItem(tr("PDF"));
    _typeBox->addItem(tr("Powerpoint"));
    _typeBox->addItem(tr("Word"));

    _linkText->setMinimumWidth(500);
    _linkText->setMinimumHeight(20);

    _btnAutoDelete->setIcon(QIcon("../Recyk/Data/img/delInfo.png"));
}

void InformationLine::setupUI()
{
    QGridLayout *mainLayout = new QGridLayout;
    mainLayout->setSpacing(5);
    mainLayout->addWidget(_typeBox, 0, 0, 1, 1, Qt::AlignCenter);
    mainLayout->addWidget(_linkText, 0, 1, 1, 1, Qt::AlignCenter);
    mainLayout->addWidget(_btnAutoDelete, 0, 2, 1, 1, Qt::AlignLeft | Qt::AlignCenter);
    mainLayout->addWidget(new QLabel(), 0, 3, 1, 7, Qt::AlignLeft);
    this->setLayout(mainLayout);
}

int InformationLine::getId()
{
    return _id;
}

QString InformationLine::getType()
{
    return ""; //_typeBox->text();
}

QString InformationLine::getLinkText()
{
    return _linkText->text();
}

void InformationLine::setId(int id)
{
    _id = id;
}

void InformationLine::setType(LinkType type)
{
    //_typeBox->setText(title);
}

void InformationLine::setLinkText(QString linkText)
{
    _linkText->setText(linkText);
}

void InformationLine::emitAutoDeletion()
{
    Logger::logMessage("InformationLine::emitAutoDeletion()");
    emit autoDeletion(_id);
}
